package com.jy.adscm.operation.base.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jy.adscm.operation.base.bean.BaseRysztm;
import com.jy.adscm.operation.base.service.BaseRysztmService;
import com.jy.adscm.support.SimpleCoreResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyy
 * @since 2019-01-08
 */
@RestController
@RequestMapping("/adscm/operation/baseRysztm")
public class BaseRysztmController {

    @Autowired
    BaseRysztmService baseRysztmService;
    @RequestMapping("/insert")
    public SimpleCoreResponse insert(BaseRysztm base,String data){
        JSONObject jsonObject = JSON.parseObject(data);
        base.setBzry(jsonObject.getString("bzry"));
        base.setIename(jsonObject.getString("iename"));
        if ("收入".equals(jsonObject.getString("szlx"))){
            base.setSzlx("1");
        } else {
            base.setSzlx("2");
        }
        return  new SimpleCoreResponse("200","新增成功",baseRysztmService.insert(base));
    }
    @RequestMapping("/update")
    public  SimpleCoreResponse update(BaseRysztm base,String data){
        System.out.println(data);
        JSONObject jsonObject = JSON.parseObject(data);
        base.setId(jsonObject.getInteger("id"));
        base.setBzry(jsonObject.getString("bzry"));
        base.setIename(jsonObject.getString("iename"));
        if ("收入".equals(jsonObject.getString("szlx"))){
            base.setSzlx("1");
        } else {
            base.setSzlx("2");
        }


        return new SimpleCoreResponse("200","修改成功",baseRysztmService.updateById(base));
    }
    @RequestMapping("/delete")
    public  SimpleCoreResponse delete(BaseRysztm base){
        return  new SimpleCoreResponse("200","删除成功",baseRysztmService.deleteById(base));
    }
    @RequestMapping("/queryAll")
    public SimpleCoreResponse queryAll(){
        return new SimpleCoreResponse("200","查询成功",baseRysztmService.queryAll());
    }
    /**
     * 查询任务发布人
     */
    @RequestMapping("/queryBzry")
    public  SimpleCoreResponse queryBzry(){
        return new SimpleCoreResponse("200","查询成功",baseRysztmService.queryBzry());
    }

    @RequestMapping("/querySzmc")
    public SimpleCoreResponse querySmc(String szlx){
        return new SimpleCoreResponse("200","查询成功",baseRysztmService.querySzmc(szlx));
    }
}

